import { PageResponse } from "@/api/types";
import { request } from '@/utils/request';
import { PageTask, Task } from "./types";

const Api = {
   getMonitor:"/monitor/job/list",
   baseTask:"/monitor/job",
   changeStatus:"monitor/job/changeStatus",
   runTask:"/monitor/job/run"
};


/**
 * 任务分页列表
 */
export function getMonitorList(params?: PageTask) {
  return request.get<PageResponse<Array<Task>>>({
    url: Api.getMonitor,
    params
  });
}

/**
 * 定时任务详情
 * @param id 任务id
 */
export function taskInfo(id: string) {
  return request.get<Task>({
    url: `${Api.baseTask}/${id}`
  });
}

/**
 * 新增定时任务
 */
export function addTask(data: Task) {
  return request.post({
    url: Api.baseTask,
    data
  });
}




/**
 * 编辑定时任务
 */
export function editTask(data: Task) {
  return request.put({
    url: Api.baseTask,
    data
  }); 
}

/**
 * 修改定时任务状态
 */
export function changeStatus(data: Task) {
  return request.put({
    url: Api.changeStatus,
    data
  }); 
}

/**
 * 删除定时任务
 */
export function deletTask(id: string) {
  return request.delete({
    url: `${Api.baseTask}/${id}`
  });
}

/**
 * 立即执行定时任务一次
 */
export function runTask(data: Task) {
  return request.put({
    url:`${Api.baseTask}`,
    data
  }); 
}






